package com.xkcoding.orm.mybatis.plus.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xkcoding.orm.mybatis.plus.entity.ReturnData;
import com.xkcoding.orm.mybatis.plus.entity.User;
import com.xkcoding.orm.mybatis.plus.mapper.UserMapper;
import com.xkcoding.orm.mybatis.plus.serviceImpl.UserServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * UserController
 * </p>
 *
 * @author andrew
 * @date Created in 2021-09-17 10:17
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserServiceImpl userService;

    @Resource
    private UserMapper userMapper;

    @GetMapping(value = "/find/all")
    public Object getAllUser(){
        PageInfo pageInfo;
        pageInfo = userService.findAllUser();
//        pageInfo = userMapper.selectList();
        return ReturnData.builder().rv(200).msg("success").data(pageInfo.getList()).build();
    }

    @GetMapping(value = "/findXml/all")
    public Object getAllXmlUser(){
        List<HashMap> list = new ArrayList<>();
        list = userService.findAllXmlUser();
        return ReturnData.builder().rv(200).msg("success").data(list).build();
    }

    @GetMapping(value = "/find/user1")
    public Object getAllUserForXml1() {
        PageHelper.startPage(6, 5);
        List<User> list =userService.list();
        PageInfo pageInfo = new PageInfo(list);
        return ReturnData.builder().rv(200).msg("success").data(pageInfo).build();
    }

    @GetMapping(value = "/find/user2")
    public Object getAllUserForXml2() {
        PageInfo pageInfo = userService.findAllXmlUser1();
        return ReturnData.builder().rv(200).msg("success").data(pageInfo).build();
    }

}
